package com.neuedu.common.core.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

//import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.validation.constraints.Size;

import lombok.Data;

import org.apache.commons.lang3.StringUtils;

/**
 * Entity基类
 *
 * @author neuedu
 */
@ApiModel("实体基类")
@Data
public class BaseEntity implements Serializable {

//    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 搜索值
     */
    @ApiModelProperty(hidden = true)
    @TableField(exist = false)
    private String searchValue;

    /**
     * 创建者
     */
    @ApiModelProperty("创建者")
    private String createBy;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @ApiModelProperty("创建时间")
    private Date createTime;

    /**
     * 更新者
     */
    @ApiModelProperty("更新者")
    private String updateBy;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("更新时间")
    private Date updateTime;

    /**
     * 备注
     */
    @Size(max = 200, message = "备注长度不能超过200")
    @ApiModelProperty("备注")
    @TableField(exist = false)
    private String remark;

    /**
     * 请求参数
     */
    @ApiModelProperty(hidden = true)
    @TableField(exist = false)
    private Map<String, Object> params;

    public String getSearchValue() {
        if (StringUtils.isNotBlank(searchValue)) {
            searchValue = searchValue.replaceAll("[('%_\\\\)]", "\\\\$0");
        }
        return searchValue;
    }

    public Map<String, Object> getParams() {
        if (params == null) {
            params = new HashMap<>();
        }
        return params;
    }

}
